<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline size="small" @submit.native.prevent>
            <el-form-item label="关键字">
              <el-input v-model="codeListData.pram.tableName" placeholder="表名称" clearable size="small">
                <el-button slot="append" icon="el-icon-search" size="small" @click="handlerSearch"/>
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>

      <el-row>
        <el-col :span="2">
          <router-link :to="{ path: '/users/detail'}">
            <el-button size="small" type="primary" class="mr10" style="float:left;">退款</el-button>
          </router-link>
        </el-col>
        <el-col :span="2">
          <el-upload class="upload" action="string"
                     :file-list="fileList"
                     :auto-upload="false"
                     :http-request="uploadFile"
                     :on-change="handleChange"
                     :on-preview="handlePreview"
                     :on-remove="handleRemove"
                     multiple="multiple">
            <el-button slot="trigger" size="small" type="primary" @click="delFile">
              选取文件
            </el-button>
          </el-upload>
        </el-col>
        <el-col :span="2">
          <el-form-item label="图文封面" prop="imageInput"
                        :rules="[{ required: true, message: '请上传图文封面', trigger: 'change' }]">
            <div class="upLoadPicBox" @click="modalPicTap('1')">
              <div v-if="pram.imageInput" class="pictrue"><img :src="pram.imageInput"></div>
              <div v-else class="upLoad">
                <i class="el-icon-camera cameraIconfont"/>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>

      <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="名称" prop="name"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="路由" type="expand">
          <template slot-scope="props">
            <el-table :data="props.row.routes" size="mini" style="width: 92%;margin-left: 8%">
              <el-table-column label="名称" prop="name"></el-table-column>
              <el-table-column label="路径" prop="path"></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="100" fixe="right" align="center">
          <template>
            <router-link :to="{ path: '/users/detail' }">
              <el-button size="small" type="text" class="mr10">编辑</el-button>
            </router-link>
            <el-button type="text" @click="dialogVisible = true">退款</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
      title="拒绝退款原因"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {listMenu} from '@/api/user.js'

export default {
  name: 'codegenList',
  data() {
    return {
      pram: {
        imageInput: ''
      },
      dialogVisible: false,
      constants: this.$constants,
      codeListData: {
        pram: {
          page: 1,
          limit: 10,
          tableName: ''
        }
      },
      tableData: [],
      data: {
        list: [],
        totalCount: 0
      },
      selectedTables: [],
      fileList: [],
      multiple: false,
      formData: ''
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    delFile() {
      this.fileList = []
    },
    handleChange(file, fileList) {
      this.fileList = fileList
    },
    uploadFile(file) {
      this.formData.append('file', file.file)
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    handleSelectChange(val) {
      console.info(val)
    },
    handlerSearch() {
      this.codeListData.pram.limit = 10
      this.codeListData.pram.page = 1
      this.getList(this.codeListData.pram)
    },
    handleClose(done) {
      this.$confirm('确认关闭').then(_ => {
        done()
      }).catch(_ => {
      })
    },
    getList(pram) {
      let that = this
      listMenu(pram).then(res => {
        console.info(res)
        if (res.data.code === '0000') {
          that.tableData = res.data.data
        } else if (res.data.code === 'tokErr001') {
          location.href = '/login'
        } else {
          this.$message({
            message: res.data.message,
            center: true,
            offset: 250,
            duration: 1500
          })
        }
      }).catch(err => {
        console.info(err)
      })
    }
  }
}
</script>
